home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB6 Code / Class 6 / Example6-6AD.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-17  |  9.2 KB  |  312 lines

  1. VERSION 5.00
  2. Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
  3. Begin VB.Form frmAuthors 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Authors"
  6.    ClientHeight    =   2625
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   4680
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   2625
  14.    ScaleWidth      =   4680
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton cmdDone 
  17.       Caption         =   "Do&ne"
  18.       Height          =   375
  19.       Left            =   3240
  20.       TabIndex        =   13
  21.       TabStop         =   0   'False
  22.       Top             =   2160
  23.       Width           =   1215
  24.    End
  25.    Begin VB.CommandButton cmdDelete 
  26.       Caption         =   "&Delete"
  27.       Height          =   375
  28.       Left            =   1680
  29.       TabIndex        =   12
  30.       TabStop         =   0   'False
  31.       Top             =   2160
  32.       Width           =   1215
  33.    End
  34.    Begin VB.CommandButton cmdEdit 
  35.       Caption         =   "&Edit"
  36.       Height          =   375
  37.       Left            =   120
  38.       TabIndex        =   11
  39.       TabStop         =   0   'False
  40.       Top             =   2160
  41.       Width           =   1215
  42.    End
  43.    Begin VB.CommandButton cmdCancel 
  44.       Caption         =   "&Cancel"
  45.       Height          =   375
  46.       Left            =   3240
  47.       TabIndex        =   10
  48.       TabStop         =   0   'False
  49.       Top             =   1680
  50.       Width           =   1215
  51.    End
  52.    Begin VB.CommandButton cmdSave 
  53.       Caption         =   "&Save"
  54.       Height          =   375
  55.       Left            =   1680
  56.       TabIndex        =   9
  57.       TabStop         =   0   'False
  58.       Top             =   1680
  59.       Width           =   1215
  60.    End
  61.    Begin VB.CommandButton cmdAddNew 
  62.       Caption         =   "&Add New"
  63.       Height          =   375
  64.       Left            =   120
  65.       TabIndex        =   8
  66.       TabStop         =   0   'False
  67.       Top             =   1680
  68.       Width           =   1215
  69.    End
  70.    Begin VB.CommandButton cmdNext 
  71.       Caption         =   "Next =>"
  72.       Height          =   255
  73.       Left            =   2520
  74.       TabIndex        =   7
  75.       TabStop         =   0   'False
  76.       Top             =   1320
  77.       Width           =   1215
  78.    End
  79.    Begin VB.CommandButton cmdPrevious 
  80.       Caption         =   "<= Previous"
  81.       Height          =   255
  82.       Left            =   1080
  83.       TabIndex        =   6
  84.       TabStop         =   0   'False
  85.       Top             =   1320
  86.       Width           =   1215
  87.    End
  88.    Begin VB.TextBox txtYearBorn 
  89.       DataField       =   "Year Born"
  90.       DataSource      =   "datAuthors"
  91.       Height          =   285
  92.       Left            =   1200
  93.       Locked          =   -1  'True
  94.       MaxLength       =   4
  95.       TabIndex        =   2
  96.       Text            =   "Text"
  97.       Top             =   840
  98.       Width           =   1215
  99.    End
  100.    Begin VB.TextBox txtAuthor 
  101.       DataField       =   "Author"
  102.       DataSource      =   "datAuthors"
  103.       Height          =   285
  104.       Left            =   1200
  105.       Locked          =   -1  'True
  106.       TabIndex        =   1
  107.       Text            =   "Text2"
  108.       Top             =   480
  109.       Width           =   3375
  110.    End
  111.    Begin VB.TextBox txtAuthorID 
  112.       DataField       =   "Au_ID"
  113.       DataSource      =   "datAuthors"
  114.       Height          =   285
  115.       Left            =   1200
  116.       Locked          =   -1  'True
  117.       TabIndex        =   3
  118.       TabStop         =   0   'False
  119.       Text            =   "Text1"
  120.       Top             =   120
  121.       Width           =   1215
  122.    End
  123.    Begin MSAdodcLib.Adodc datAuthors 
  124.       Height          =   330
  125.       Left            =   2520
  126.       Top             =   120
  127.       Visible         =   0   'False
  128.       Width           =   2055
  129.       _ExtentX        =   3625
  130.       _ExtentY        =   582
  131.       ConnectMode     =   0
  132.       CursorLocation  =   3
  133.       IsolationLevel  =   -1
  134.       ConnectionTimeout=   15
  135.       CommandTimeout  =   30
  136.       CursorType      =   3
  137.       LockType        =   3
  138.       CommandType     =   1
  139.       CursorOptions   =   0
  140.       CacheSize       =   50
  141.       MaxRecords      =   0
  142.       BOFAction       =   0
  143.       EOFAction       =   0
  144.       ConnectStringType=   1
  145.       Appearance      =   1
  146.       BackColor       =   -2147483643
  147.       ForeColor       =   -2147483640
  148.       Orientation     =   0
  149.       Enabled         =   -1
  150.       Connect         =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\VBDB\Working\Biblio.mdb"
  151.       OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\VBDB\Working\Biblio.mdb"
  152.       OLEDBFile       =   ""
  153.       DataSourceName  =   ""
  154.       OtherAttributes =   ""
  155.       UserName        =   ""
  156.       Password        =   ""
  157.       RecordSource    =   "SELECT * FROM Authors ORDER BY Author"
  158.       Caption         =   "Adodc1"
  159.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  160.          Name            =   "MS Sans Serif"
  161.          Size            =   8.25
  162.          Charset         =   0
  163.          Weight          =   400
  164.          Underline       =   0   'False
  165.          Italic          =   0   'False
  166.          Strikethrough   =   0   'False
  167.       EndProperty
  168.       _Version        =   393216
  169.    End
  170.    Begin VB.Label Label3 
  171.       Caption         =   "Year Born"
  172.       Height          =   255
  173.       Left            =   120
  174.       TabIndex        =   5
  175.       Top             =   840
  176.       Width           =   1215
  177.    End
  178.    Begin VB.Label Label2 
  179.       Caption         =   "Author Name"
  180.       Height          =   255
  181.       Left            =   120
  182.       TabIndex        =   4
  183.       Top             =   480
  184.       Width           =   1215
  185.    End
  186.    Begin VB.Label Label1 
  187.       Caption         =   "Author ID"
  188.       Height          =   255
  189.       Left            =   120
  190.       TabIndex        =   0
  191.       Top             =   120
  192.       Width           =   1215
  193.    End
  194. Attribute VB_Name = "frmAuthors"
  195. Attribute VB_GlobalNameSpace = False
  196. Attribute VB_Creatable = False
  197. Attribute VB_PredeclaredId = True
  198. Attribute VB_Exposed = False
  199. Option Explicit
  200. Private Sub ValidateData(AllOK As Boolean)
  201. Dim Message As String
  202. Dim InputYear As Integer, CurrentYear As Integer
  203. AllOK = True
  204. Message = ""
  205. 'Check for name
  206. If Len(txtAuthor.Text) = 0 Then
  207.   Message = "You must enter an Author Name." + vbCrLf
  208.   txtAuthor.SetFocus
  209.   AllOK = False
  210. End If
  211. 'Check length and range on Year Born
  212. InputYear = Val(txtYearBorn.Text)
  213. CurrentYear = Val(Format(Now, "yyyy"))
  214. If Len(txtYearBorn.Text) <> 0 Then
  215.   If InputYear > CurrentYear Or InputYear < CurrentYear - 150 Then
  216.     Message = Message + "Year Born must be between" & Str(CurrentYear - 150) & " and" & Str(CurrentYear) & "."
  217.     txtYearBorn.SetFocus
  218.     AllOK = False
  219.   End If
  220. End If
  221. If Not (AllOK) Then
  222.   MsgBox Message, vbOKOnly + vbInformation, "Validation Error"
  223. End If
  224. End Sub
  225. Private Sub cmdAddNew_Click()
  226. Call SetState("Add")
  227. End Sub
  228. Private Sub cmdCancel_Click()
  229. Call SetState("View")
  230. End Sub
  231. Private Sub cmdDelete_Click()
  232. Dim Response As Integer
  233. Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete")
  234. If Response = vbNo Then
  235.   Exit Sub
  236. End If
  237. End Sub
  238. Private Sub cmdEdit_Click()
  239. Call SetState("Edit")
  240. End Sub
  241. Private Sub cmdNext_Click()
  242. datAuthors.Recordset.MoveNext
  243. If datAuthors.Recordset.EOF Then
  244.   Beep
  245.   datAuthors.Recordset.MoveLast
  246. End If
  247. End Sub
  248. Private Sub cmdPrevious_Click()
  249. datAuthors.Recordset.MovePrevious
  250. If datAuthors.Recordset.BOF Then
  251.   Beep
  252.   datAuthors.Recordset.MoveFirst
  253. End If
  254. End Sub
  255. Private Sub cmdSave_Click()
  256. Dim Valid As Boolean
  257. Call ValidateData(Valid)
  258. If Not (Valid) Then Exit Sub
  259. MsgBox "Record saved.", vbOKOnly + vbInformation, "Save"
  260. Call SetState("View")
  261. End Sub
  262. Private Sub SetState(AppState As String)
  263. Select Case AppState
  264. Case "View"
  265.   txtAuthorID.BackColor = vbWhite
  266.   txtAuthor.Locked = True
  267.   txtYearBorn.Locked = True
  268.   cmdPrevious.Enabled = True
  269.   cmdNext.Enabled = True
  270.   cmdAddNew.Enabled = True
  271.   cmdSave.Enabled = False
  272.   cmdCancel.Enabled = False
  273.   cmdEdit.Enabled = True
  274.   cmdDelete.Enabled = True
  275.   cmdDone.Enabled = True
  276.   txtAuthor.SetFocus
  277. Case "Add", "Edit"
  278.   txtAuthorID.BackColor = vbWhite
  279.   txtAuthor.Locked = False
  280.   txtYearBorn.Locked = False
  281.   cmdPrevious.Enabled = False
  282.   cmdNext.Enabled = False
  283.   cmdAddNew.Enabled = False
  284.   cmdSave.Enabled = True
  285.   cmdCancel.Enabled = True
  286.   cmdEdit.Enabled = False
  287.   cmdDelete.Enabled = False
  288.   cmdDone.Enabled = False
  289.   txtAuthor.SetFocus
  290. End Select
  291. End Sub
  292. Private Sub Form_Activate()
  293. Call SetState("View")
  294. End Sub
  295. Private Sub txtAuthor_KeyPress(KeyAscii As Integer)
  296. If KeyAscii = vbKeyReturn Then
  297.   txtYearBorn.SetFocus
  298.   Exit Sub
  299. End If
  300. End Sub
  301. Private Sub txtYearBorn_KeyPress(KeyAscii As Integer)
  302. If KeyAscii = vbKeyReturn Then
  303.   txtAuthor.SetFocus
  304.   Exit Sub
  305. End If
  306. If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Or KeyAscii = vbKeyBack Then
  307.   Exit Sub
  308.   Beep
  309.   KeyAscii = 0
  310. End If
  311. End Sub
  312.